
local mt = ac.skill['急速冲刺']
mt.title = '急速冲刺'
mt.art = [[ReplaceableTextures\CommandButtons\BTNAttackGround.blp]]
mt.is_order = 1
mt.targettype = '点'
mt.smart_cast = 1
mt.range = 99999
mt.slotid = 6
mt.cost = 0
mt.hotkey = 'D'
mt.tip = [[
主动：
朝鼠标放标冲刺]]

function mt:on_cast_shot()
    local hero = self.owner
    local player = hero.owner
    local point = self.target
    local angle = hero:get_point()/point
    local distance = math.min(hero:get_point()*point,800)
    local point = hero:get_point() - {angle,distance}
    if hero.jump_mover then
        hero.jump_mover:remove()
    end
    hero:add_restriction '定身'
    hero.jump_mover = ac.mover('line')
    {
        mover = hero,
        angle = angle,
        speed = 2200,
        distance = distance,
        on_move = function(_,point)
            if point then
                local effect = hero:create_shadow(point,angle,0.2)
                effect:play_animation('stand')
            end
        end,
        on_remove = function()
            hero:remove_restriction '定身'
            hero:notify('单位-D闪完成',hero,angle)
        end
    }
end

ac.sync:event '同步-冲刺'(function(_,player,x,y)
    local hero = player.hero
    local unit = player:get_select_unit()
    if hero and unit==hero then
        local point = ac.point(x,y)
        local skill = hero:find_skill '急速冲刺'
        if skill then
            skill:cast(point)
        end
    end
end)

ac.message:event '键盘按下'(function(_,code)
    if code==KEY.D then
        local x, y = ac.message.mouse()
        ac.sync('同步-冲刺',x,y)
    end
end)

register_hero(function(player,hero)
    hero:add_skill('急速冲刺')
end)
